
function toggleEmailCodeBlock() {
    var emailCodeBlock = document.getElementById('emailCodeBlock');
    if (emailCodeBlock.style.display === 'none') {
        emailCodeBlock.style.display = 'block';
    } else {
        emailCodeBlock.style.display = 'none';
    }
}
toggleEmailCodeBlock();
function sendcode(){
   
	var email= $("#email").val(); 
    var username= $("#username").val();
    var qq= $("#qq").val();
    var phone= $("#phone").val();
    var code_input= $("#code_input").val();
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
	    type : "POST",
	    url : "./Ajax.php",
	    data : {
	        act:'Sendcode',
	        email:email,
	        user:username,
	        qq:qq,
	        phone:phone,
	        code_input:code_input
	    },
	    dataType : 'json',
	    success : function(data){
	        layer.close(ii);
	        if(data.code == 200){
	            layer.msg(data.msg, {
						icon: 1,
						time: 1000
				});
			    toggleEmailCodeBlock();	
			    refreshCaptcha();//刷新验证码
	        }else{
	            layer.msg(data.msg, {
					icon: 2,
					time: 1000
				});
		    	refreshCaptcha();//刷新验证码	
	        }
	    },
		error:function(data){
    		layer.close(ii);
    		layer.msg('服务器错误!', {
					icon: 2,
					time: 1000
				});
    		refreshCaptcha();
		}
	});
}
 // 支付函数
function payNow(trade_no,type) {
    var url = './api.php?s=submit_pay&type=' + type + '&trade_no=' + trade_no;
    window.location.href = url;
}

function check_reg(){
    var user=$("#username").val();
	var pass=$("#password").val();
	var qq=$("#qq").val();
	var email=$("#email").val();
	var code=$("#code").val();
	var phone= $("#phone").val();
	var ii = layer.load(5, {shade:[0.1,'#fff']});
	$.ajax({
	    type : "POST",
	    url : "./Ajax.php",
	    data : {
	        act:"Reg",
	        user,
	        pass,
	        qq,
	        email,
	        code,
	        phone
	    },
	    dataType : 'json',
		timeout: 15000, //ajax请求超时时间15s
		success : function(res){
		    layer.close(ii);
		    if(res.code==200){
		        layer.msg(res.msg, {
						icon: 1,
						time: 1000
				},function(){
				    window.location.href="./login";
				});
		    }else if(res.code == 1){
		        layer.msg(res.msg,{
		            time: 1000
		        },function(){
		            var paymsg = '';
                    $.each(res.data.paytype, function(key, value) {
                        paymsg += '<button class="btn btn-default btn-block" onclick="payNow(\'' + res.data.trade_no + '\', \'' + value.name + '\')" style="margin-top:10px;"><img width="20" src="/Core/assets/icon/' + value.name + '.ico" class="logo">' + value.showname + '</button>';
                    });
                    
                    layer.alert('<center><h2>￥ ' + res.data.need + '</h2><hr>' + paymsg + '<hr>提示：支付完成后即可直接登录</center>', {
                        btn:[],
                        title:'支付确认页面',
                        closeBtn: false
                    });
		        });
		    }else{
		        layer.msg(res.msg, {
						icon: 2,
						time: 1000
				});
		    }
		},
		error:function(data){
    		layer.close(ii);
    	    layer.msg("服务器错误！", {
						icon: 3,
						time: 1000
				});
		}
	});
}
                       
$(function(){
$("#sendcode").click(function(){
	sendcode();
	return false;
})
	$("#reg").click(function(){
		check_reg();
		return false;
	})
})